//axios插件的配置参数  用来干嘛的？做一些初始化的配置
import axios from 'axios';
const AxiosIns = axios.create({
  timeout: 2000,
  //baseURL: 'http://192.168.10.136:8087',
  baseURL:'http://118.190.205.4:8087',
  //baseURL:'http://app.ihotelvip.com/',
  params: {

  }
})

//请求拦截处理 
AxiosIns.interceptors.request.use(config => {
  config.data = Object.assign({
    // "login_ip": "string",
    "operation": "string",
    "timestamp": 0,
    "version": "string"
  }, config.data)

  return config
}, error => {

})
// import AxiosIns from './axiosConfig2'

let ajaxMethod = ['get', 'post'];
let api = {};
ajaxMethod.forEach((method) => {
  //数组取值的两种方式
  api[method] = function (uri, data) {
    return new Promise(function (resolve, reject) {
      AxiosIns[method](uri, data).then(res => {
        if (!res.data.errCode) {
          resolve(res);
        } else {
          if (res.data.errCode == 10001) {
            // setTimeout(() => {
            //   window.location.href = "/login"
            // }, 500)
          }
        }
      }).catch((response) => {})
    })
  }
});
export default api;
